package com.example.day5_fragment2.fragment;


import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.day5_fragment2.MainActivity;
import com.example.day5_fragment2.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class OneFragment extends Fragment {


    public OneFragment() {

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_one, container, false);
        //发送
        view.findViewById(R.id.send).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Message message = Message.obtain();
                message.what = 101;
                message.obj = "hahah";
                //判断fragment2是否加载
                MainActivity mainActivity = (MainActivity) getActivity();
                if(mainActivity.twoFragment != null){
                    TwoFragment.handler.sendMessage(message);
                }




            }
        });
        return view;
    }

}
